<template>
  <div>
    <form>
      <input type="text" v-model="user.email">
      <input type="password" v-model="user.password">
      <button type="button" @click="login">登录</button>
    </form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user:{
        email: 'lulu@qq.com',
        password: 'lulu'
      }
    }
  },
  async beforeMount() {
  },
  methods: {
    async login() {
      if (!this.user.email && !this.user.password) alert('账号密码不能为空')
      let { email, password } = this.user
      this.$store.dispatch('login', { email, password }).then(res => {
        if (res.success) this.$router.push('/admin')
        else alert(res.error)
      })
    }
  }
}
</script>

